package com.amazon.dao;



import com.amazon.bo.KeyWords;
import com.amazon.bo.ProductClass;
import com.amazon.dao.base.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ProductClassDao extends BaseDao<ProductClass> {

    //保存
    public boolean save(ProductClass k){
        try{
            add(k);
            return true;
        }catch (Exception ex){
            return false;
        }
    }
    //查询
    public ProductClass getProductClassBycode(String code){
        ProductClass kw=execute(session ->
                session.createNativeQuery("SELECT * FROM product_class WHERE product_class_code=:classcode",ProductClass.class)
                        .setParameter("classcode",code).uniqueResult());
        return kw;
    }
    //更新
    public Boolean updateClass(ProductClass k){
        try{
            update(k);
            return true;
        }catch (Exception ex){
            return false;
        }
    }
    //关键词列表
    public List<ProductClass> getClassList(final int page, final int pageSize) {
        List<ProductClass> results = execute(session -> (List<ProductClass>) session
                .createNativeQuery("SELECT * FROM product_class ", ProductClass.class)
                .setFirstResult((page - 1) * pageSize)
                .setMaxResults(pageSize)
                .getResultList());
        return results != null ? results : new ArrayList<ProductClass>();
    }
}
